package com.cy.web;

import com.alibaba.fastjson.JSONArray;
import com.cy.bean.Student;
import com.cy.service.StudentService;
import com.cy.util.CacheRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StudentController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private CacheRedisService cacheRedisService;

    @RequestMapping("/studentlogin")
    public @ResponseBody String login(String sacc,String spwd){
        System.out.println("执行登录功能");
        Student student = studentService.login(sacc,spwd);
        String obj = JSONArray.toJSONString(student);
        /*将用户信息存入redis*/
        if (obj != "" || obj != null) {
            cacheRedisService.add("userInfo", obj);
        }
        return obj;
    }

    @RequestMapping("/checkStudentRes")
    public @ResponseBody String checkStudentRes(){
        String msg = "false";
        try {
            if (cacheRedisService.get("distinguishResult") != null) {
                msg = cacheRedisService.get("distinguishResult");
                System.out.println("redis--value="+msg);
            }else {
                msg = "false";
            }
        }catch (Exception e){
            msg = "false";
        }
        System.out.println(msg+"++++++++++++++");
        return msg;
    }
}
